import {Injectable} from "@angular/core";
import {Origin} from "./origin";
import {Observable} from "rxjs";
import {API} from "../../../constants/constants";
import {MsgResult} from "../../../models/msg-result";
import {RequestUtil} from "../../../util/request-util";


@Injectable()
export class OriginService{

  origin: Origin;
  constructor(
    private requestUtil: RequestUtil
  ) { }


  getLampblackData(origin: Origin): Observable<MsgResult> {
    let params = "sites=" + origin.sites + "&startTimeStr=" + origin.startTime + "&endTimeStr=" + origin.endTime;
    return this.requestUtil.get(API.getLampblackData, params);
  }

  exportExcelData(origin: Origin): any {
    console.log(API.exportExcelOriginalData);
    let params = "&sites=" + origin.sites + "&startTimeStr=" + origin.startTime + "&endTimeStr=" + origin.endTime;
    // return this.requestUtil.get(API.exportExcelOriginalData, params);
    window.location.href = API.exportExcelLampblacklData + params;
  }

  //返回数据成功
  // private success(res: Response) {
  //   let json = res.json();
  //   console.log("response data:"+ JSON.stringify(json));
  //   return json as MsgResult;
  // }

  //返回数据失败
  // private error(error: Response | any) {
    // In a real world app, we might use a remote logging infrastructure
  //   let errMsg: string;
  //   if (error instanceof Response) {
  //     const body = error.json() || '';
  //     const err = body.error || JSON.stringify(body);
  //     errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
  //   } else {
  //     errMsg = error.message ? error.message : error.toString();
  //   }
  //   console.log(errMsg);
  //   return Observable.throw(errMsg);
  // }


}
